<?php
class VariablesSiteValues extends AppModel
{
  var $name = 'VariablesSiteValues';
  var $useTable = "variables_sites_values";
  var $id = "vv_id";
  var $primaryKey = "vv_id";

  function get_variables_site_values($site_id, $variable_id)
  {
		$cond = "vv_s_id=$site_id and vv_v_id = $variable_id";
		$rows = $this->findAll($cond, "vv_s_id, vv_v_id, vv_value_key, vv_value, vv_create_date, vv_user_id", "vv_v_id", null, 1, null);
		return $rows;
	}

	function serialize($values, $key)
	{
    $rows = array();
    foreach ($values as $id => $valArray)
    {
      $rows[$valArray[$this->name][$key]] = $valArray[$this->name];
    }
    return $rows;
  }

	function getFieldValue($field, $key, $key_value)
	{
		$rows = $this->field($field, array("$key" => "$key_value"));
		return $rows;
  }

  function getFieldsValue($whereArray, $fields)
  {
		$rows = $this->find($whereArray, $fields, null, null);
		return $rows;
  }

  function setPrimaryKey ($key)
  {
    $this->primaryKey = $key;
  }

	function getListVariableValues($site_id, $variable_id)
  {
		$cond = "vv_s_id=$site_id and vv_v_id = $variable_id";
    return $this->generateList($cond, "vv_value_key", null, "{n}.VariablesSiteValues.vv_value_key", "{n}.VariablesSiteValues.vv_value");
  }

}
?>
